package utils;

import pojo.Student;

import java.util.List;

public class StudentUtil {
    /**
     * 根据学号获取学生索引
     * @param list
     * @param sno
     * @return
     */
    public static int getIndexBySno(List<Student> list, String sno){
        if(list.isEmpty()){
            return -1;
        }
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getSno().equals(sno)){
                return i;
            }
        }
        return -1;
    }

    /**
     * 根据身份证号获取学生索引
     * @param list
     * @param idNumber
     * @return
     */
    public static int getIndexByIdNumber(List<Student> list, String idNumber){
        if(list.isEmpty()){
            return -1;
        }
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getId_number().equals(idNumber)){
                return i;
            }
        }
        return -1;
    }

    /**
     * 打印列表
     * @param list
     * @param <T>
     */
    public static <T> void printList(List<T> list){
        if(list.isEmpty()){
            System.out.println("学生信息不存在，请重新尝试");
        }
        System.out.println(getBetween());
        list.forEach(System.out::println);
        System.out.println(getBetween());
    }

    private static String getBetween() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 150; i++) {
            sb.append("--");
        }
        return sb.toString();
    }
}
